package tt.dz.egobus.servicemanager.business.distance;

import tt.dz.egobus.servicemanager.business.point.BusPoint;
import tt.dz.egobus.servicemanager.business.point.PointAlgorithmHelp;

import java.util.Comparator;

/**
 * @author Anson
 * @date 17-3-23
 * @name 计算不同亮点距离
 * @since 1.0.2
 */
public class DistanceComparator implements Comparator<BusPoint> {

    private final double x;

    private final double y;

    public DistanceComparator(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public int compare(BusPoint o1, BusPoint o2) {
        double powerLength1 = PointAlgorithmHelp.accPointLength(o1, this.x, this.y);
        double powerLength2 = PointAlgorithmHelp.accPointLength(o2, this.x, this.y);
        double acc = powerLength1 - powerLength2;
        return acc > 0 ? 1 : (acc < 1 ? -1 : 0);
    }


}
